cmake_minimum_required(VERSION 3.2)
project(Server_framework)

include(cmake/utils.cmake)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS  "$ENV{CXXFLAGS} -rdynamic -O3 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -g")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(LIB_SRC sylar/config.cpp
            sylar/bytearray.cpp
            sylar/address.cpp
            sylar/fd_manager.cpp
            sylar/fiber.cpp
            sylar/http/http.cpp
            sylar/http/http_parser.cpp
            sylar/http/http_session.cpp
            sylar/http/http11_parser.rl.cc
            sylar/http/httpclient_parser.rl.cc
            sylar/hook.cpp
            sylar/iomanager.cpp
            sylar/log.cpp
            sylar/scheduler.cpp
            sylar/socket.cpp
            sylar/socket_stream.cpp
            sylar/stream.cpp
            sylar/tcp_server.cpp
            sylar/timer.cpp
            sylar/thread.cpp
            sylar/util.cpp)

#将指定目录添加到编译器的头文件搜索路径之下，指定的目录被解释成当前源码路径的相对路径。
include_directories(.)
include_directories(sylar/include/)

#指定第三方库所在的路径
link_directories(/usr/local/lib)

#将指定的源文件生成链接文件，然后添加到工程去
add_library(sylar SHARED ${LIB_SRC})
force_redefine_file_macro_for_sources(sylar) # //__FILE__

#在指定目录下搜索一个库, 保存在变量MY_LIB中
#find_library(MY_LIB libmylib.a ./)
find_library(PTHREAD pthread)

set(LIB_LIB
        sylar
        dl
        pthread
        yaml-cpp
    )

#message("***",${LIB_LIB})

add_executable(test tests/test.cpp)
add_dependencies(test sylar)
force_redefine_file_macro_for_sources(test)
#将目标文件与库文件进行链接 第一个是目标文件，后面是库文件
target_link_libraries(test sylar ${LIB_LIB})



#通过指定的源文件列表构建出可执行目标文件
add_executable(test_config tests/test_config.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_config sylar)
force_redefine_file_macro_for_sources(test_config)
target_link_libraries(test_config sylar ${LIB_LIB})


add_executable(test_thread tests/test_thread.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_thread sylar)
force_redefine_file_macro_for_sources(test_thread)
target_link_libraries(test_thread sylar ${LIB_LIB})


add_executable(test_util tests/test_util.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_util sylar)
force_redefine_file_macro_for_sources(test_util)
target_link_libraries(test_util sylar ${LIB_LIB})


add_executable(test_fiber tests/test_fiber.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_fiber sylar)
force_redefine_file_macro_for_sources(test_fiber)
target_link_libraries(test_fiber sylar ${LIB_LIB})

add_executable(test_schedule tests/test_schedule.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_schedule sylar)
force_redefine_file_macro_for_sources(test_schedule)
target_link_libraries(test_schedule sylar ${LIB_LIB})


add_executable(test_iomanager tests/test_IOManager.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_iomanager sylar)
force_redefine_file_macro_for_sources(test_iomanager)
target_link_libraries(test_iomanager sylar ${LIB_LIB})

add_executable(test_hook tests/test_hook.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_hook sylar)
force_redefine_file_macro_for_sources(test_hook)
target_link_libraries(test_hook sylar ${LIB_LIB})


add_executable(test_address tests/test_address.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_address sylar)
force_redefine_file_macro_for_sources(test_address)
target_link_libraries(test_address sylar ${LIB_LIB})

add_executable(test_socket tests/test_socket.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_socket sylar)
force_redefine_file_macro_for_sources(test_socket)
target_link_libraries(test_socket sylar ${LIB_LIB})

add_executable(test_bytearray tests/test_bytearray.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_bytearray sylar)
force_redefine_file_macro_for_sources(test_bytearray)
target_link_libraries(test_bytearray sylar ${LIB_LIB})

add_executable(test_http tests/test_http.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_http sylar)
force_redefine_file_macro_for_sources(test_http)
target_link_libraries(test_http sylar ${LIB_LIB})

add_executable(test_parser tests/test_parser.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_parser sylar)
force_redefine_file_macro_for_sources(test_parser)
target_link_libraries(test_parser sylar ${LIB_LIB})

add_executable(echo_server example/echo_server.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(echo_server sylar)
force_redefine_file_macro_for_sources(echo_server)
target_link_libraries(echo_server sylar ${LIB_LIB})

add_executable(test_tcp_server tests/test_tcp_server.cpp)
#先生成test_config对syalr的依赖，然后再去通过上面一条命令生成test_config
add_dependencies(test_tcp_server sylar)
force_redefine_file_macro_for_sources(test_tcp_server)
target_link_libraries(test_tcp_server sylar ${LIB_LIB})

#EXECUTABLE_OUTPUT_PATH:表示最终的目标二进制位置
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#LIBRARY——OUTPUT_PATH：表示最终的共享库
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
